﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:NJL_TEMP_ORDER
    /// </summary>
    public partial class NJL_TEMP_ORDER : INJL_TEMP_ORDER
    {
        public NJL_TEMP_ORDER()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from NJL_TEMP_ORDER");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(NJL.Model.NJL_TEMP_ORDER model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into NJL_TEMP_ORDER(");
            strSql.Append("ID,NJL_SYS_BASE_ID,ORDER_NO,BOOK_NAME,BOOK_MOBILE,ORDER_TOTAL,PAY_USE,ORDER_STATE,PAY_MAP_TYPE_CODE,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME,PAY_DATE_TIME)");
            strSql.Append(" values (");
            strSql.Append("@ID,@NJL_SYS_BASE_ID,@ORDER_NO,@BOOK_NAME,@BOOK_MOBILE,@ORDER_TOTAL,@PAY_USE,@ORDER_STATE,@PAY_MAP_TYPE_CODE,@CREATE_USER_NAME,@CREATE_USER_ID,@CREATE_DATE_TIME,@PAY_DATE_TIME)");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@ORDER_NO", SqlDbType.VarChar,50),
					new SqlParameter("@BOOK_NAME", SqlDbType.VarChar,20),
					new SqlParameter("@BOOK_MOBILE", SqlDbType.VarChar,20),
					new SqlParameter("@ORDER_TOTAL", SqlDbType.Money,8),
					new SqlParameter("@PAY_USE", SqlDbType.Text),
					new SqlParameter("@ORDER_STATE", SqlDbType.Int,4),
					new SqlParameter("@PAY_MAP_TYPE_CODE", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@PAY_DATE_TIME", SqlDbType.DateTime)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.NJL_SYS_BASE_ID;
            parameters[2].Value = model.ORDER_NO;
            parameters[3].Value = model.BOOK_NAME;
            parameters[4].Value = model.BOOK_MOBILE;
            parameters[5].Value = model.ORDER_TOTAL;
            parameters[6].Value = model.PAY_USE;
            parameters[7].Value = model.ORDER_STATE;
            parameters[8].Value = model.PAY_MAP_TYPE_CODE;
            parameters[9].Value = model.CREATE_USER_NAME;
            parameters[10].Value = model.CREATE_USER_ID;
            parameters[11].Value = model.CREATE_DATE_TIME;
            parameters[12].Value = model.PAY_DATE_TIME;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NJL.Model.NJL_TEMP_ORDER model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update NJL_TEMP_ORDER set ");
            strSql.Append("NJL_SYS_BASE_ID=@NJL_SYS_BASE_ID,");
            strSql.Append("ORDER_NO=@ORDER_NO,");
            strSql.Append("BOOK_NAME=@BOOK_NAME,");
            strSql.Append("BOOK_MOBILE=@BOOK_MOBILE,");
            strSql.Append("ORDER_TOTAL=@ORDER_TOTAL,");
            strSql.Append("PAY_USE=@PAY_USE,");
            strSql.Append("ORDER_STATE=@ORDER_STATE,");
            strSql.Append("PAY_MAP_TYPE_CODE=@PAY_MAP_TYPE_CODE,");
            strSql.Append("CREATE_USER_NAME=@CREATE_USER_NAME,");
            strSql.Append("CREATE_USER_ID=@CREATE_USER_ID,");
            strSql.Append("CREATE_DATE_TIME=@CREATE_DATE_TIME,");
            strSql.Append("PAY_DATE_TIME=@PAY_DATE_TIME");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@ORDER_NO", SqlDbType.VarChar,50),
					new SqlParameter("@BOOK_NAME", SqlDbType.VarChar,20),
					new SqlParameter("@BOOK_MOBILE", SqlDbType.VarChar,20),
					new SqlParameter("@ORDER_TOTAL", SqlDbType.Money,8),
					new SqlParameter("@PAY_USE", SqlDbType.Text),
					new SqlParameter("@ORDER_STATE", SqlDbType.Int,4),
					new SqlParameter("@PAY_MAP_TYPE_CODE", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@PAY_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = model.NJL_SYS_BASE_ID;
            parameters[1].Value = model.ORDER_NO;
            parameters[2].Value = model.BOOK_NAME;
            parameters[3].Value = model.BOOK_MOBILE;
            parameters[4].Value = model.ORDER_TOTAL;
            parameters[5].Value = model.PAY_USE;
            parameters[6].Value = model.ORDER_STATE;
            parameters[7].Value = model.PAY_MAP_TYPE_CODE;
            parameters[8].Value = model.CREATE_USER_NAME;
            parameters[9].Value = model.CREATE_USER_ID;
            parameters[10].Value = model.CREATE_DATE_TIME;
            parameters[11].Value = model.PAY_DATE_TIME;
            parameters[12].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_TEMP_ORDER ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_TEMP_ORDER ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NJL.Model.NJL_TEMP_ORDER GetModel(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,NJL_SYS_BASE_ID,ORDER_NO,BOOK_NAME,BOOK_MOBILE,ORDER_TOTAL,PAY_USE,ORDER_STATE,PAY_MAP_TYPE_CODE,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME,PAY_DATE_TIME from NJL_TEMP_ORDER ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            NJL.Model.NJL_TEMP_ORDER model = new NJL.Model.NJL_TEMP_ORDER();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = ds.Tables[0].Rows[0]["ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"] != null && ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString() != "")
                {
                    model.NJL_SYS_BASE_ID = ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ORDER_NO"] != null && ds.Tables[0].Rows[0]["ORDER_NO"].ToString() != "")
                {
                    model.ORDER_NO = ds.Tables[0].Rows[0]["ORDER_NO"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BOOK_NAME"] != null && ds.Tables[0].Rows[0]["BOOK_NAME"].ToString() != "")
                {
                    model.BOOK_NAME = ds.Tables[0].Rows[0]["BOOK_NAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BOOK_MOBILE"] != null && ds.Tables[0].Rows[0]["BOOK_MOBILE"].ToString() != "")
                {
                    model.BOOK_MOBILE = ds.Tables[0].Rows[0]["BOOK_MOBILE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ORDER_TOTAL"] != null && ds.Tables[0].Rows[0]["ORDER_TOTAL"].ToString() != "")
                {
                    model.ORDER_TOTAL = decimal.Parse(ds.Tables[0].Rows[0]["ORDER_TOTAL"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PAY_USE"] != null && ds.Tables[0].Rows[0]["PAY_USE"].ToString() != "")
                {
                    model.PAY_USE = ds.Tables[0].Rows[0]["PAY_USE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ORDER_STATE"] != null && ds.Tables[0].Rows[0]["ORDER_STATE"].ToString() != "")
                {
                    model.ORDER_STATE = int.Parse(ds.Tables[0].Rows[0]["ORDER_STATE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PAY_MAP_TYPE_CODE"] != null && ds.Tables[0].Rows[0]["PAY_MAP_TYPE_CODE"].ToString() != "")
                {
                    model.PAY_MAP_TYPE_CODE = ds.Tables[0].Rows[0]["PAY_MAP_TYPE_CODE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER_NAME"] != null && ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString() != "")
                {
                    model.CREATE_USER_NAME = ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER_ID"] != null && ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString() != "")
                {
                    model.CREATE_USER_ID = ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"] != null && ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "")
                {
                    model.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PAY_DATE_TIME"] != null && ds.Tables[0].Rows[0]["PAY_DATE_TIME"].ToString() != "")
                {
                    model.PAY_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["PAY_DATE_TIME"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,NJL_SYS_BASE_ID,ORDER_NO,BOOK_NAME,BOOK_MOBILE,ORDER_TOTAL,PAY_USE,ORDER_STATE,PAY_MAP_TYPE_CODE,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME,PAY_DATE_TIME ");
            strSql.Append(" FROM NJL_TEMP_ORDER ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,NJL_SYS_BASE_ID,ORDER_NO,BOOK_NAME,BOOK_MOBILE,ORDER_TOTAL,PAY_USE,ORDER_STATE,PAY_MAP_TYPE_CODE,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME,PAY_DATE_TIME ");
            strSql.Append(" FROM NJL_TEMP_ORDER ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "NJL_TEMP_ORDER";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method

        /// <summary>
        /// 查询用户编号和支付渠道
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListInPayMap(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.ID,a.NJL_SYS_BASE_ID,a.ORDER_NO,a.BOOK_NAME,a.BOOK_MOBILE,a.ORDER_TOTAL,a.PAY_USE,a.ORDER_STATE,a.PAY_MAP_TYPE_CODE,a.CREATE_USER_NAME,a.CREATE_USER_ID,a.CREATE_DATE_TIME,a.PAY_DATE_TIME,b.TYPE_NAME");
            strSql.Append(" FROM NJL_TEMP_ORDER a inner join NJL_SYS_CS_PAY_MAP b on a.PAY_MAP_TYPE_CODE=b.TYPE_CODE");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by a.CREATE_DATE_TIME desc");
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}

